﻿@using MyBlog
@{
    var blogUser = ViewBag.blogUser as AccountModel;
    var cates = ViewBag.cates as List<CategoryModel>;
    var comments = ViewBag.comments as List<ArticleCommentModel>;
    var articlesGroupByDate = ViewBag.articlesGroupByDate as List<Tuple<string, int>>;
    var hotArticles = ViewBag.hotArticles as List<ArticleModel>;
    var hotReArticles = ViewBag.hotReArticles as List<ArticleModel>;
    var canEdit = Convert.ToBoolean(ViewBag.CanEdit);
}

<div class="dright_top">
    <div class="top_title">公告</div>
    <div class="top_content">
        <p>
            @if (UserSession.LoginUserInfo != null && UserSession.AccountId.Same(blogUser.Account))
            {
                <a title="点击进入个人信息设置" href="@Url.Action("userinfo")"><img src="@Url.Action("getuserhead")" /></a>
            }
            else {<img src="@Url.Action("getuserhead")" />}
        </p>
        <ul>
            <li>昵称：<span class="green blod">@blogUser.NickName</span></li>
            <li>博龄：<span class="green blod">@DateTime.Now.YearMonthDiff(blogUser.RegTime)</span></li>
            <li>粉丝：<a class="green blod" href="@Url.Action("UserCenter")/#3">@blogUser.ConcernMeUsers.Count</a></li>
            <li>关注：<a class="green blod" href="@Url.Action("UserCenter")/#2">@blogUser.MyConcernUsers.Count</a></li>
            @if (UserSession.LoginUserInfo == null || (UserSession.LoginUserInfo != null && !UserSession.AccountId.Same(blogUser.Account)))
            {
                if (UserSession.LoginUserInfo != null && WebCache.GetMyConcernUsers(UserSession.AccountId).Exists(x => x.ConcernUID.Same(blogUser.Account)))
                {
                    <li><span class="red"><i class="icon-heart"></i> 已关注</span>&nbsp;<a class="concern-link" href="javascript:;" onclick="concern(this,@WebCache.GetMyConcernUsers(UserSession.AccountId).Find(x => x.ConcernUID.Same(blogUser.Account)).ID)">取消关注</a></li>
                }
                else {
                    <li><a class="concern-link" href="javascript:;" onclick="concern(this,0)"><i class="icon-heart"></i> 加关注</a></li>
                }
            }
            <li class="edit-uinfo">
                <a href="@Url.Action("usercenter")"><i class="icon-bell"></i> @(UserSession.LoginUserInfo != null && UserSession.AccountId.Same(blogUser.Account) ? "我的动态" : "他的动态")</a>
            </li>
            @if (canEdit)
            {
                <li class="edit-uinfo">
                    <a href="@Url.Action("userinfo")"><i class="icon-edit"></i> 个人信息设置</a>
                </li>
            }
        </ul>
    </div>
</div>
@*<div id="dvcalendar" class="easyui-calendar" style="width:100%;height:200px;"></div>*@
<div class="dright-sidebar">
    <div class="sidebar-title">随笔分类</div>
    @if (cates.Default().Count() > 0)
            {
        <ul>
            @foreach (var item in cates)
                {
                <li><a href="@Url.Action("articles",new { cid = item.ID })">@(item.CategoryName.SubStr(12))(<lable class="red">@item.ArticleModels.Count</lable>)</a></li>
            }
        </ul>
    }
    else
    {
        <span>暂无分类~</span>
    }
</div>
<div class="dright-sidebar">
    <div class="sidebar-title">随笔档案</div>
    @if (articlesGroupByDate.Default().Count() > 0)
            {
        <ul>
            @foreach (var item in articlesGroupByDate)
                {
                <li>
                    <a href="@Url.Action("articles", new { begin = item.Item1.Replace("年", "-") + item.Item2.ToString().Replace("月", "-01"), isMonth = true })" title="@(item.Item2)篇">@(item.Item1)(<lable class="red">@item.Item2</lable>)</a>
                </li>
            }
        </ul>
    }
    else
    {
        <span>暂无档案~</span>
    }
</div>
<div class="dright-sidebar">
    <div class="sidebar-title">阅读排行榜</div>
    @if (hotArticles.Default().Count() > 0)
            {
        <ul>
            @foreach (var item in hotArticles)
                {
                <li><a href="@Url.Action("article",new { id = item.ID })" title="@(item.ReadCount+"人阅读")">@(item.Title)(<label class="red">@item.ReadCount</label>)</a></li>
            }
        </ul>
    }
    else
    {
        <span>暂无排行~</span>
    }
</div>
<div class="dright-sidebar">
    <div class="sidebar-title">评论排行榜</div>
    @if (hotReArticles.Default().Count() > 0)
            {
        <ul>
            @foreach (var item in hotReArticles)
                {
                <li><a href="@Url.Action("article",new { id = item.ID })" title="@(item.ArticleCommentModels.Count+"条评论")">@(item.Title)(<label class="red">@item.ArticleCommentModels.Count</label>)</a></li>
            }
        </ul>
    }
    else
    {
        <span>暂无排行~</span>
    }
</div>
<div class="dright-comment-sidebar">
    <div class="sidebar-title">最新评论</div>
    @if (comments.Default().Count() > 0)
            {
                int i = 0;
        <ul>
            @foreach (var item in comments)
                {
                <li class="dright-sidebar-comment-title">@(++i).  <label  class="spuid inline-b">@WebCache.GetNickName(item.CommentUid)</label>回复：<a target="_blank" href="@Url.Action("article", new { id = item.Article.ID })">@item.Article.Title</a></li>
                <li class="dright-sidebar-comment-content">@item.Content.StripHTML().SubStr(28)</li>
                @*<li class="dright-sidebar-comment-author">--@WebCache.GetNickName(item.CommentUid)</li>*@
            }
        </ul>
    }
    else
    {
        <span>暂无评论~</span>
    }
</div>

<script type="text/javascript">
    function concern(a, id) {
        if (!layerCheckLogin(true)) {
            return;
        }
        $.post('@Url.Action("concern")', { id: id }, function (o) {
            if (o.State == 1) {
                var c = parseInt($(a).parent().prev().prev().find('a').first().text());
                if (id == 0) {
                    $(a).parent().prev().prev().find('a').first().text(++c);
                    $(a).parent().html('<span class=\'red\'><i class="icon-heart"></i> 已关注</span>&nbsp;<a class="concern-link" href="javascript:;" onclick="concern(this,' + o.Data + ')">取消关注</a>');
                } else {
                    $(a).parent().prev().prev().find('a').first().text(--c);
                    $(a).parent().html('<a class="concern-link" href="javascript:;" onclick="concern(this,0)"><i class="icon-heart"></i> 加关注</a>');
                }
            } else {
                layerAlert("关注失败：" + o.Message);
            }
        })
    }
</script>